<template>
	<view class="">
		<view v-if="infoList.length <= 0" class="p-2 mt-3" style="margin: 100rpx auto;">
			<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂无消息"></u-empty>
		</view>
		<view class="bg-white p-3 mb-2" v-for="item of infoList" :key="item.data.id" @click="toInfo(item)">
			<view class="flex justify-between">
				<text class="font_36">{{ item.title }}</text>
				<view class="flex">
					<text class="font_24 c_9">{{ dataTime(item.data.create_at) }}</text>
					<view v-if="item.status == 0"><u-badge :isDot="true" type="error"></u-badge></view>
				</view>
			</view>
			<view class="font-sm c_9 mt-1">{{ item.data.content }}</view>
		</view>
	</view>
</template>

<script>
import { messageIndex } from '@/api/my/inform.js';
import util from '@/common/js/util.js';
export default {
	data() {
		return {
			infoList: []
		};
	},
	computed: {
		dataTime(val) {
			return function(val) {
				return util.getDateBeforeNow(val);
			};
		}
	},
	onShow() {
		this.getInfo();
	},
	onLoad() {
		// 分享
		wx.showShareMenu({
			withShareTicket: true,
			menus: ['shareAppMessage', 'shareTimeline']
		});
	},
	methods: {
		getInfo() {
			messageIndex({ token: uni.getStorageSync('userInfo').token || '' })
				.then(res => {
					if (res.code == 0) {
						this.infoList = res.data;
					} else {
						uni.$u.toast(res.msg);
					}
				})
				.catch(err => {
					console.log('获取消息列表失败', err);
				});
		},
		toInfo(val) {
			console.log(val);
			uni.navigateTo({
				url: '/subPages/my/inform/list?type=' + val.data.type + '&title=' + val.title
			});
		}
	}
};
</script>

<style lang="scss" scoped></style>
